package com.xiongwei.manageback.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpLogic;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ArrayUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/test")
public class TestController {

    @GetMapping("/login")
    public String login(@RequestParam Integer id,@RequestParam String password){
        if (Integer.valueOf(15).equals(id) && "123456".equals(password)){
            StpUtil.login(id,false);
            return "登录成功";
        }
        return "失败";
    }

    @GetMapping("/logout")
    public String logout(){
        StpUtil.logout();
        return "登出成功";
    }

    @SaCheckLogin
    @GetMapping("/isLogin")
    public String isLogin(){
        return "当前为登录状态";
    }

    @SaCheckPermission("user:select2")
    @GetMapping("/list")
    public List<String> getUserList(){
        List<String> userList = Arrays.asList("Jacky", "Mike", "Lucy", "Nancy");
        return userList;
    }
}
